package com.cloud.portmana.entity.dao.impl;

import java.util.List;

import com.cloud.portmana.entity.GlobalVariable;
import com.cloud.portmana.entity.dao.IBgGlobalVariableDao;
import com.cloud.sysmana.dto.FaultVarDS;
import com.cloud.util.base.BaseHibernateDao;
import com.cloud.util.other.StringUtil;
import com.cloud.util.page.PageInfo;

public class BgGlobalVariableDao extends BaseHibernateDao<GlobalVariable, String>implements IBgGlobalVariableDao {

	@Override
	public void addGlobalVariable(GlobalVariable globalVariable) {
		this.saveEntity(globalVariable);

	}

	@Override
	public void delGlobalVariable(String id) {
		this.executeQuery("delete from global_variable where id = '"+id+"'");

	}

	@Override
	public void updateGlobalVariable(GlobalVariable globalVariable) {
		this.updateEntity(globalVariable);

	}

	@Override
	public List<GlobalVariable> getList() {
		
		return this.getEntities("from GlobalVariable");
	}

	@Override
	public PageInfo getListPage(PageInfo pageInfo, FaultVarDS faultVarDS) {
		String hsql = "select * from global_variable ";
		String countSql = "select COUNT(*) from global_variable ";
		
		String whereSql = "where 1=1 ";
		String orderSql = " ORDER BY name ";
		
		if(faultVarDS !=null){		
			
			//获取车型的品牌
			if(!StringUtil.isEmpty(faultVarDS.getOnefield())){
				whereSql += " and name like '%" + StringUtil.addQuote(faultVarDS.getOnefield()) + "%'";
			}
			
		}
		pageInfo.setEntityClass(GlobalVariable.class);
		pageInfo.setListHbSql(hsql+whereSql+orderSql);
		pageInfo.setTotalCountHbSQL(countSql+whereSql);
		return pageInfo;
	}

	@Override
	public GlobalVariable getGlobalVariableByid(String id) {
		
		return this.findById(id);
	}

}
